<!DOCTYPE html>
<html>
{include file="public/header" /}
<body>

<div class="layui-fluid" id="app">

    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">

            <div class="layui-card">

                <div class="layui-card-body">
                    <form class="layui-form" action="" lay-filter="component-form-group">

                        <div class="layui-card-body" style="padding: 15px;">

                            <input type="hidden" name="id" value="{$item.id}">
                            <div class="layui-form-item">
                                <label class="layui-form-label">名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="pinpai" value="{$item.pinpai}"  class="layui-input" lay-verify="required">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">图片</label>

                                <div class="layui-input-inline " style="width: auto;">

                                    <div class="layui-upload-drag" id="pic1" style="padding: 2px">
                                        <!--{if $item.pinpai_logo2=='null'}-->
                                        <!--<img class="layui-upload-img" style="width: auto;height: 120px; object-fit: cover;" src="/res/img/thumb.png">-->
                                        <!--{else}-->
                                        <!--<img  class="layui-upload-img" style="width: auto;height: 120px; object-fit: cover;" src="{$item.pinpai_logo2}">-->
                                        <!--{/if}-->
                                        <img v-if="list=='null'" class="layui-upload-img" style="width: 120px;height: 120px; object-fit: cover;" src="/res/img/logo.png">
                                        <img v-else class="layui-upload-img" style="width: auto;height: 120px; object-fit: cover;" src="{$item.pinpai_logo2}">
                                        <input type="hidden" name="pinpai_logo" value="{$item.pinpai_logo}" >
                                    </div>

                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="bianji">保存</button>
                                </div>
                            </div>

                        </div>

                    </form>
                </div>


            </div>
        </div>
    </div>

    <script>
        var app = new Vue({
            el: '#app',
            data: {
                list:""
            },

        });
    app.list="{$item.pinpai_logo2}";
        layui.use(['form', 'laydate', 'upload'], function () {
            var $ = layui.$
                , element = layui.element
                , layer = layui.layer
                , laydate = layui.laydate
                , form = layui.form;
            var upload = layui.upload;

            form.render(null, 'component-form-group');

            laydate.render({
                elem: '#LAY-component-form-group-date'
            });



            //拖拽上传
            upload.render({
                elem: '#pic1'
                , url: '/tool/qiniu/upload'
                , before: function () {
                    layer.load(2);
                }
                , done: function (res) {
                    layer.closeAll();
                    console.log(res)
                    $('#pic1 img').attr('src', res.data.url);
                    $('#pic1 input').val(res.data.pic);
                }
            });


            /* 监听提交 */
            form.on('submit(bianji)', function (data) {

                $.post("{:url('editpinpai')}", data.field, function (res) {
                    if (res.code == 1) {

                        //将数据传入到父元素
//                        parent.app.items.push(data.field);
//                        $('.layui-form')[0].reset();
                        parent.init();
                        parent.layer.closeAll();
                        parent.layer.msg(res.msg, {icon: 1})
//                        $('#phone').val('');


                        return false;
                    } else {
                        parent.layer.msg(res.msg, {icon: 2})
                        return false;
                    }
                });


                return false;
            });
        });
    </script>
</div>
</body>
</html>










